import request from '@/utils/request'

//提交订单
export const submitOrder = (orderData, username) => {
  return axios.post(`/api/order/submitOrder?username=${username}`, orderData);
};

//获取订单列表
export const getOrders = () => {
  return axios.get('/api/orders', {
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`
    }
  })
}

//获取订单详情
export function getOrderDetail(orderId) {
  return request.get(`/orders/${orderId}/detail`)
}

//提交收获地址
export const submitShippingAddress = (shippingData, username) => {
  return axios.post(`/api/order/shipping?username=${username}`, shippingData)
}


//创建订单
export const createOrder = (username) => {
  return request.get(`/orders/username/${username}`, {
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`
    }
  })
}

// 提交 Payment 信息
export const submitPayment = (orderId, paymentData) => {
  return request.post(`/orders/${orderId}/payment`, paymentData);
};

// 提交 Shipping 信息
export const submitShipping = (orderId, shippingData) => {
  return request.post(`/orders/${orderId}/shipping`, shippingData);
};